﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UploadFacePic.aspx.cs" Inherits="test_UploadFacePic" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
    <link href="/css/top.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
		//允许上传的图片类型
		var extensions = 'jpg,jpeg,gif,png';
		//保存缩略图的地址.
		var saveUrl = '../service/UploadFacePic.ashx';
		//保存摄象头白摄图片的地址.
		var cameraPostUrl = '../service/UploadFacePic.ashx';
		//头像编辑器flash的地址.
		var editorFlaPath = '../images/AvatarEditor.swf';

		function useCamera()
		{
			var content = '<embed height="464" width="514" ';
			content +='flashvars="type=camera';
			content +='&postUrl='+cameraPostUrl+'?op=camera';
			content += '&saveUrl='+saveUrl+'?op=camera" ';
			content +='pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" ';
			content +='allowscriptaccess="always" quality="high" ';
			content +='src="'+editorFlaPath+'"/>';
			document.getElementById('avatar_editor').innerHTML = content;
		}
		function buildAvatarEditor(pic_id,pic_path,post_type)
		{
			var content = '<embed height="464" width="514"'; 
			content+='flashvars="type='+post_type;
			content+='&photoUrl='+pic_path;
			content+='&photoId='+pic_id;
			content+='&postUrl='+cameraPostUrl+'?op=save_avata';
			content+='&saveUrl='+saveUrl+'?op=save_avata"';
			content+=' pluginspage="http://www.macromedia.com/go/getflashplayer"';
			content+=' type="application/x-shockwave-flash"';
			content+=' allowscriptaccess="always" quality="high" src="'+editorFlaPath+'"/>';
			document.getElementById('avatar_editor').innerHTML = content;
		}
		/**
		* 提供给FLASH的接口 ： 没有摄像头时的回调方法
		*/
		function noCamera(){
		    alert("俺是小狗, 俺没有camare ：）");
		}
					
		/**
		* 提供给FLASH的接口：编辑头像保存成功后的回调方法
		*/
		function avatarSaved(){
		    alert('保存成功，哈哈');
		}
			
		/**
		* 提供给FLASH的接口：编辑头像保存失败的回调方法, msg 是失败信息，可以不返回给用户, 仅作调试使用.
		*/
		function avatarError(msg){
            alert(msg);
			//alert("上传失败了呀，哈哈");
		}

		function checkFile()
		{
		    var path = document.getElementById('FileData').value;
		    var ext = getExt(path);
		    var re = new RegExp("(^|\\s|,)" + ext + "($|\\s|,)", "ig");
		    if(extensions != '' && (re.exec(extensions) == null || ext == '')) {
		        alert('对不起，只能上传jpg, gif, png类型的图片');
		        return false;
		    }
		    showLoading();
		    return true;
		}

		function getExt(path) {
		    return path.lastIndexOf('.') == -1 ? '' : path.substr(path.lastIndexOf('.') + 1, path.length).toLowerCase();
		}
        function showLoading()
		{
		    document.getElementById('loading_gif').style.visibility = 'visible';
		}
	    function hideLoading()
	    {
	        document.getElementById('loading_gif').style.visibility = 'hidden';
	    }
    </script>
</head>
<body>
    <form id="form1" method="post" enctype="multipart/form-data" name="upform" target="upload_target" action="/service/UploadFacePic.ashx?op=fileupload" >
        <div>
            <input type="file" name="FileData" id="FileData"/>
		    <input style="margin-right:20px;" type="submit" name="" value="上传形象照" onclick="return checkFile();" /><br />
		    <div style="padding:10px 0;color:#666;">
		        你最好上传一张真人照片证明你是地球人，也可以  <a style="color:#cc3300;" href="javascript:void(0);" onclick="useCamera()">快使用摄像头，喝喝哈嘿！~</a>
		    </div>
		    <span style="visibility:hidden;" id="loading_gif"><img src="../images/loading.gif" align="absmiddle" />上传中，请稍侯......</span>
            <div id="avatar_editor"></div>
        </div>
    </form>
    <iframe src="about:blank" name="upload_target" style="display:none;"></iframe>
</body>
</html>
